<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="Content-Language" content="zh-cn">
    <meta name="apple-mobile-web-app-capable" content="no"/>
    <meta name="apple-touch-fullscreen" content="yes"/>
    <meta name="format-detection" content="telephone=no,email=no"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="white">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <meta http-equiv="Expires" content="0">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-control" content="no-cache">
    <meta http-equiv="Cache" content="no-cache">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>商品支付</title>
    <style>
        body{background:#f2f2f4;}
        body,html{width:100%;height:100%;}
        *,:after,:before{box-sizing:border-box;}
        *{margin:0;padding:0;}
        img{max-width:100%;}
        #header{height:60px;border-bottom:2px solid #eee;background-color:#fff;text-align:center;line-height:60px;}
        #header h1{font-size:20px;}
        #main{overflow:hidden;margin:0 auto;padding:20px;padding-top:80px;width:992px;max-width:100%;}
        #main .left{float:left;width:40%;box-shadow:0 0 60px #b5f1ff;}
        .left p{margin:10px auto;}
        .make{padding-top:15px;border-radius:10px;background-color:#fff;box-shadow:0 3px 3px 0 rgba(0,0,0,.05);color:#666;text-align:center;transition:all .2s linear;}
        .make .qrcode{margin:auto;}
        .make .money{margin-bottom:0;color:#f44336;font-weight:600;font-size:18px;}
        .info{padding:15px;width:100%;border-radius:0 0 10px 10px;background:#32343d;color:#f2f2f2;text-align:center;font-size:14px;}
        #main .right{float:right;padding-top:25px;width:60%;color:#ccc;text-align:center;}
        @media (max-width:768px){
            #main{padding-top:30px;}
            #main .left{width:100%;}
            #main .right{display:none;}
        }
    </style>
    <script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
    <link rel="stylesheet" type="text/css" th:href="@{/css/QRCode.css}">
    <script type="text/javascript" th:src="@{/js/clipboard.min.js}"></script>
    <script type="text/javascript" th:src="@{/js/qrcode.js}"></script>
<!--    <script th:src="@{/js/layer.js}"></script>-->
    <link type="text/css" href="https://www.layuicdn.com/layui-v2.5.6/css/layui.css" />
    <script src="https://www.layuicdn.com/layui-v2.5.6/layui.js"></script>
    <script type="text/javascript">


    </script>
</head>

<body>

<div id="main">
    <div class="left">
        <div class="make">
            <p><img th:src="@{/img/alipay-logo.png}" alt="" style="height:30px;"></p>
            <p>商户订单号：[[${orderCode}]]</p>
            <p class="money" id="price" style="font-weight:bold; color:green">订单金额：￥[[${amount}]]</p>
            <p class="money" id="account" style="font-weight:bold; color:green">收款账号：[[${account}]]</p><a onclick='copy("copy_account")' th:data-clipboard-text="${account}" id="copy_account" class="btn  btn-primary btn-lg btn-block">复制</a>
            <p class="money" id="name" style="font-weight:bold; color:green">收款姓名：[[${name}]]</p><a onclick='copy("copy_name")' th:data-clipboard-text="${name}" id="copy_name" class="btn  btn-primary btn-lg btn-block">复制</a>
            <center>
                <div id="qrcode">
                    <img id="image"  style="display: block;">
                    <h2>距离该订单过期还有</h2>
                    <div class="time-item">
                        <strong id="hour_show"><s id="h"></s>0时</strong>
                        <strong id="minute_show"><s></s>0分</strong>
                        <strong id="second_show"><s></s>0秒</strong>
                    </div>
                </div></p>
            </center>
            <center>
                <a id="alipayh5url_1"></a>
                <a id="alipayh5url_2"></a>
            </center>
            <div class="info">
                <p><font color="#FF0000" size="+1">1、请按照金额付款，错误支付无法上分</font></p>
                <p><font color="#FF0000" size="+1">2、请在规定时间内付款，超时支付无法上分</font></p>

            </div>
        </div>
    </div>

</div>
</body>

<script th:inline="javascript">
    var ctx = [[@{/}]];
</script>
<script>
    var layer ;
    layui.use(['laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element'], function() {
        layer = layui.layer //弹层
    });
    var _AP = {}
    var ua = navigator.userAgent.toLowerCase();

    var ipad = ua.match(/(iPad).*OS\s([\d_]+)/),

        isIphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/),

        isAndroid = ua.match(/(Android)\s+([\d.]+)/);

    var isWeChat = /micromessenger/.test(ua);

    var noIntentTest = /aliapp|360 aphone|weibo|windvane|ucbrowser/.test(ua);
    var hasIntentTest = /chrome|samsung/.test(ua);
    var isAndroid = /android|adr/.test(ua) && !(/windows phone/.test(ua));
    var isIos = /iphone|ipad|ipod|ios|macintosh/.test(ua);
    var canIntent = !noIntentTest && hasIntentTest && isAndroid;

    // 确定浏览器类型
    var isChrome = false;
    var isWebview = false;
    if (ua.match(/(?:chrome|crios)\/([\d\.]+)/)) {
        isChrome = true;
        if (ua.match(/version\/[\d+\.]+\s*chrome/)) {
            isWebview = true;
        }
    }

    var isOriginalChrome = isAndroid && isChrome && !isWebview;
    window.isOriginalChrome = isOriginalChrome && canIntent;
    if (ua.indexOf('m353')>-1 && !noIntentTest) {
        canIntent = false;
    }

    // 安卓走iframe方式唤起
    if (ua.indexOf('android')>-1 && !noIntentTest) {
        canIntent = false;
    }
    var key = "&amp;";
    var param = '[[${orderCode}]]';

    var url = '[[${payUrl}]]';
    var opentype = '[[${opentype}]]';
    var intDiff = parseInt(5*60);//倒计时总秒数量
    debugger;
    var qrcode = "";
    var newUrl = url.replace(new RegExp(key, 'g'), "&");
    qrcode = newUrl;
    new QRCode(document.getElementById("qrcode"), {
        text: newUrl,
        width: 250,
        height: 250,
        colorDark: "#000000",
        colorLight: "#ffffff",
        correctLevel: 3
    });


    function daoqi() {

        layer.confirm("订单已过期,请重新提交", {
            icon: 2,
            title: '支付失败',
            btn: ['确认'] //按钮
        }, function () {

        });
    }

    function isMobile() {
        var userAgentInfo = navigator.userAgent;

        var mobileAgents = [ "Android", "iPhone", "SymbianOS", "Windows Phone", "iPad","iPod"];

        var mobile_flag = false;

        //根据userAgent判断是否是手机
        for (var v = 0; v < mobileAgents.length; v++) {
            if (userAgentInfo.indexOf(mobileAgents[v]) > 0) {
                mobile_flag = true;
                break;
            }
        }

        var screen_width = window.screen.width;
        var screen_height = window.screen.height;

        //根据屏幕分辨率判断是否是手机
        if(screen_width < 500 && screen_height < 800){
            mobile_flag = true;
        }

        return mobile_flag;
    }

    function copy(btnid) {
        var clipboard = new ClipboardJS("#"+btnid);
        clipboard.on("success",function (element) {//复制成功的回调
            // console.info("复制成功，复制内容：    " + element.text);
            // layer.alert("复制成功", {
            //     icon: 6,
            //     title: "信息",
            //     btn:['关闭']
            // });
            layer.alert('复制成功,跳转到支付宝后输入复制的账号！', {
                skin: 'layui-layer-molv' //样式类名  自定义样式
                ,closeBtn: 1    // 是否显示关闭按钮
                ,anim: 1 //动画类型
                ,btn: ['跳转支付','返回扫码'] //按钮
                ,icon: 6    // icon
                ,yes:function(){
                    window.location.href = newUrl;
                },btn2:function(){

                }
            });
            //
        });

        clipboard.on("error",function (element) {//复制失败的回调
            console.info(element);
        })
    }

    function timer(intDiff){
        window.setInterval(function(){
            var day=0,
                hour=0,
                minute=0,
                second=0;//时间默认值
            if(intDiff > 0){
                day = Math.floor(intDiff / (60 * 60 * 24));
                hour = Math.floor(intDiff / (60 * 60)) - (day * 24);
                minute = Math.floor(intDiff / 60) - (day * 24 * 60) - (hour * 60);
                second = Math.floor(intDiff) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
            }
            if (minute == '00' && second == '00') document.getElementById('qrcode').innerHTML='<br/><br/><br/><br/><br/><h2>二维码超时 请重新发起交易</h2><br/><br/><br/>';
            if (minute <= 9) minute = '0' + minute;
            if (second <= 9) second = '0' + second;
            $('#day_show').html(day+"天");
            $('#hour_show').html('<s id="h"></s>'+hour+'时');
            $('#minute_show').html('<s></s>'+minute+'分');
            $('#second_show').html('<s></s>'+second+'秒');
            intDiff--;
            if (intDiff < 0) {
                daoqi();
            }
        }, 1000);
    }

    window.onload = function(){
        timer(intDiff);
        if(isMobile()){
            //copy("btn_account");
            layer.alert('为确保正常上分，请输入实际付款人姓名，输入成功后，复制账号，跳转支付宝支付，不要修改金额和备注！', {
                skin: 'layui-layer-molv' //样式类名  自定义样式
                ,closeBtn: 0    // 是否显示关闭按钮
                ,anim: 1 //动画类型
                ,btn: ['输入姓名'] //按钮
                ,icon: 6    // icon
                ,yes:function(index){

                    layer.close(index);
                    layer.prompt({
                        title: '请填写付款人真实姓名'
                        ,formType: 0,   //输入框类型，支持0（文本）默认1（密码）2（多行文本）
                        value: '',   //初始时的值，默认空字符
                        maxlength: 100, //可输入文本的最大长度，默认500
                        area: ['200px', '350px'], //自定义文本域宽高
                        btn: ['确认'],
                        closeBtn: 0
                    },function(val, index1){
                        // 只有当点击确认时才会执行这里
                        var config = {
                            url: ctx + "api/v1/upOrder",
                            type: "post",
                            dataType: "json",
                            data: { orderId: param,name:val },
                            success: function(result) {
                                layer.close(index1)// 关闭当前弹窗
                            }
                        };
                        $.ajax(config);

                    })
                }
            });



        }
    }


</script>
</body>
</html>
